package com.oak.broke.model.vip.v1;

import com.oak.broke.model.vip.dto.api.SaveVipUserDTO;
import com.oak.broke.model.vip.dto.api.UpdateVipUserDTO;
import com.oak.broke.model.vip.dto.api.VipRenewalDTO;
import com.oak.broke.model.vip.service.IVipUserService;
import com.oak.broke.model.vip.vo.api.BaseVipInfoVO;
import com.oak.broke.model.vip.vo.api.VipUserVO;
import com.oak.broke.model.vip.base.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author tanghan
 * @Description 获取vip用户api
 * @date 2023/04/13/ 09:49:00
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/vip/user/")
@Api(tags = "会员用户api")
public class VipUserV1Api {

    @Autowired
    private IVipUserService vipUserService;

    /**
     * 查询所有会员信息
     *
     * @param vipUserType 会员用户类型
     * @return
     */
    @ApiOperation("查询所有会员用户")
    @PostMapping("/listAll")
    public ResponseMessage<List<VipUserVO>> listAll(@RequestParam("vipUserType") String vipUserType) {
        return ResponseMessage.success(vipUserService.listAllVipUser(vipUserType));
    }

    @ApiOperation("保存会员用户")
    @PostMapping("/save")
    public ResponseMessage saveVipUser(@RequestBody @Valid SaveVipUserDTO saveVipDTO) {
        log.info("保存会员用户信息，请求参数入参为:{}", saveVipDTO.toString());
        vipUserService.saveVipUser(saveVipDTO);
        return ResponseMessage.success();
    }

    /**
     * 会员续费
     *
     * @param vipRenewal
     * @return
     */
    @ApiOperation("会员续费")
    @PostMapping("/vipRenewal")
    public ResponseMessage vipRenewal(@RequestBody @Valid VipRenewalDTO vipRenewal) {
        vipUserService.vipRenewal(vipRenewal);
        return ResponseMessage.success();
    }

    /**
     * 查询会员信息
     *
     * @param vipUserId
     * @return
     */
    @ApiOperation("查询会员信息")
    @GetMapping("/vipUserInfo")
    public ResponseMessage<VipUserVO> vipUserInfo(@RequestParam("vipUserId") String vipUserId) {
        return ResponseMessage.success(vipUserService.selectVipUserInfo(vipUserId));
    }

    @ApiOperation("更新会员信息")
    @PostMapping("/updateVipUser")
    public ResponseMessage updateVipUser(@RequestBody UpdateVipUserDTO updateVipUser) {
        vipUserService.updateVipUser(updateVipUser);
        return ResponseMessage.success();
    }

    @ApiOperation("获取会员信息")
    @GetMapping("/getVipInfo")
    public ResponseMessage<BaseVipInfoVO> getVipInfo(String userRelationCode, String vipUserType) {
        return ResponseMessage.success(vipUserService.selectVipInfo(userRelationCode, vipUserType));
    }
}
